package com.zzsin.gtestreporter.report;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.LinkedList;
import java.util.List;

public class Testcase {
    private Node node;

    private String name = "";
    private String result = "";
    private String time = "";
    private String timestamp = "";

    private int failure_count = 0;

    private List<String> failureList = new LinkedList<String>();

    public Testcase(Node node) {
        this.node = node;

        // <testcase name="EyerCoreBufferTest_Init" status="run" result="completed" time="0.36" timestamp="2021-05-14T14:02:03" classname="EyerCoreBuffer" />
        name        = this.node.getAttributes().getNamedItem("name").getTextContent() + "";
        result      = this.node.getAttributes().getNamedItem("result").getTextContent() + "";
        time        = this.node.getAttributes().getNamedItem("time").getTextContent() + " s";
        timestamp   = this.node.getAttributes().getNamedItem("timestamp").getTextContent() + "";

        NodeList nodeList = this.node.getChildNodes();
        for(int i=0; i<nodeList.getLength(); i++) {
            Node failureNode = nodeList.item(i);
            if(!failureNode.getNodeName().equals("failure")){
                continue;
            }
            String txt = failureNode.getTextContent();
            // System.out.println(txt);
            failureList.add(txt);
        }

        failure_count = failureList.size();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public List<String> getFailureList() {
        return failureList;
    }

    public void setFailureList(List<String> failureList) {
        this.failureList = failureList;
    }

    public int getFailure_count() {
        return failure_count;
    }

    public void setFailure_count(int failure_count) {
        this.failure_count = failure_count;
    }
}
